'use strict';

(function (app) {

//创建控制器
    app.register.controller('schpacketCtrl', ['$scope', '$http', '$filter', '$rootScope', 'sendfrom2zh', function ($scope, $http, $filter, $rootScope, sendfrom2zh) {
        $rootScope.mask=true;
        var count = 10;
        $scope.count = count;
        $scope.clientId = "";
        $scope.sendfrom = "c_s";
        $scope.packettype = "";
        $scope.startdate = moment().add(-1,"h").startOf("m");
        $scope.enddate = moment();
        $scope.sendfrom2zh = sendfrom2zh;
        $scope.pageChanged = function () {
            $rootScope.loading_text = "努力加载中..."
            $http.post("./data/schpacket", {
                    curPage: $scope.currentPage,
                    count: count,
                    clientid: $scope.clientId,
                    sendfrom: $scope.sendfrom,
                    packettype: $scope.packettype,
                    startdate: $scope.startdate.format("YYYY-MM-DD HH:mm:ss"),
                    enddate: $scope.enddate.format("YYYY-MM-DD HH:mm:ss"),

                })
                .success(function (response) {
                    $scope.data = response.Datas;
                    $scope.currentPage = response.CurPage
                    $scope.totalPage = response.TotalPage
                });
            $log.log('Page changed to: ' + $scope.currentPage);
        };
        $scope.sch = function () {
            $rootScope.loading_text = "努力加载中...";
            console.log($scope.startdate)
            $http.post("./data/schpacket", {
                    curPage: 1,
                    count: count,
                    clientid: $scope.clientId,
                    sendfrom: $scope.sendfrom,
                    packettype: $scope.packettype,
                    startdate: $scope.startdate.format("YYYY-MM-DD HH:mm:ss"),
                    enddate: $scope.enddate.format("YYYY-MM-DD HH:mm:ss")


                })
                .success(function (response) {
                    $scope.data = response.Datas;
                    $scope.currentPage = response.CurPage
                    $scope.totalPage = response.TotalPage
                });
        };
        $scope.maxSize = 10;
        $scope.totalPage = 1;
        $scope.currentPage = 1;

        var all_ptypes = [
            {value: "", text: "全部"},
            {value: "连接服务器", text: "连接服务器"},
            {value: "连接返回", text: "连接返回"},
            {value: "发布消息", text: "发布消息"},
            {value: "发布返回", text: "发布返回"},
            {value: "发布收到", text: "发布收到"},
            {value: "发布释放", text: "发布释放"},
            {value: "发布完成", text: "发布完成"},
            {value: "订阅主题", text: "订阅主题"},
            {value: "订阅返回", text: "订阅返回"},
            {value: "取消订阅", text: "取消订阅"},
            {value: "取消订阅返回", text: "取消订阅返回"},
            {value: "心跳请求", text: "心跳请求"},
            {value: "心跳回应", text: "心跳回应"},
            {value: "连接断开", text: "连接断开"}
        ]
        var c_s_ptypes = [
            {value: "", text: "全部"},
            {value: "连接服务器", text: "连接服务器"},
            {value: "发布消息", text: "发布消息"},
            {value: "发布返回", text: "发布返回"},
            {value: "发布收到", text: "发布收到"},
            {value: "发布释放", text: "发布释放"},
            {value: "发布完成", text: "发布完成"},
            {value: "订阅主题", text: "订阅主题"},
            {value: "取消订阅", text: "取消订阅"},
            {value: "心跳请求", text: "心跳请求"},
            {value: "连接断开", text: "连接断开"}

        ]
        var s_c_ptypes = [
            {value: "", text: "全部"},
            {value: "连接返回", text: "连接返回"},
            {value: "发布消息", text: "发布消息"},
            {value: "发布返回", text: "发布返回"},
            {value: "发布收到", text: "发布收到"},
            {value: "发布释放", text: "发布释放"},
            {value: "发布完成", text: "发布完成"},
            {value: "订阅返回", text: "订阅返回"},
            {value: "取消订阅返回", text: "取消订阅返回"},
            {value: "心跳回应", text: "心跳回应"}

        ]
        $scope.chgtype = function () {
            if ($scope.sendfrom == "") {
                $scope.packettypes = all_ptypes;

            } else if ($scope.sendfrom == "c_s") {
                $scope.packettypes = c_s_ptypes;

            } else if ($scope.sendfrom == "s_c") {
                $scope.packettypes = s_c_ptypes;

            }
        }
        $scope.chgtype()

    }])
})(app);